package model

import (
	"gorm.io/gorm"
	"homepage_srv/homepage"
	"smart-health-platforms/config"
	"time"
)

// 商品相册表
type GoodAlbums struct {
	Id              uint64         `gorm:"column:id;type:bigint UNSIGNED;comment:相册图片唯一id;primaryKey;not null;" json:"id"`          // 相册图片唯一id
	GoodId          uint64         `gorm:"column:good_id;type:bigint UNSIGNED;comment:商品id;not null;" json:"good_id"`               // 商品id
	Title           string         `gorm:"column:title;type:varchar(255);comment:标题;" json:"title"`                                 // 标题
	ImageUrl        string         `gorm:"column:image_url;type:varchar(512);comment:图片URL;not null;" json:"image_url"`             // 图片URL
	Pattern         int8           `gorm:"column:pattern;type:tinyint;comment:运行模式：1竖滚 2横滚;default:NULL;" json:"pattern"`           // 运行模式：1竖滚 2横滚
	ImgStatus       int8           `gorm:"column:img_status;type:tinyint;comment:图片状态:1正常 2下线 3异常;default:NULL;" json:"img_status"` // 图片状态:1正常 2下线 3异常
	EventUploadTime time.Time      `gorm:"column:event_upload_time;type:datetime(3);default:NULL;" json:"event_upload_time"`
	CreatedAt       time.Time      `gorm:"column:created_at;type:datetime(3);comment:添加时间;default:CURRENT_TIMESTAMP(3);" json:"created_at"` // 添加时间
	UpdatedAt       time.Time      `gorm:"column:updated_at;type:datetime(3);default:CURRENT_TIMESTAMP(3);" json:"updated_at"`
	DeletedAt       gorm.DeletedAt `gorm:"column:deleted_at;type:datetime(3);default:NULL;" json:"deleted_at"`
}

// 关联数据库
func (ga *GoodAlbums) TableName() string {
	return "good_albums"
}

// 商品相册列表
func (ga *GoodAlbums) Albums(goodId int64) (albumsList []*GoodAlbums, err error) {
	err = config.DB.Where("good_id = ?", goodId).Find(&albumsList).Error
	return
}

// 轮播图查询
func (ga *GoodAlbums) Carousel() (albumsList []*homepage.Carousel, err error) {
	err = config.DB.Model(&GoodAlbums{}).Find(&albumsList).Error
	return
}

// 广告弹窗
func (ga *GoodAlbums) Advertisement() (albumsList []*GoodAlbums, err error) {
	err = config.DB.Model(&GoodAlbums{}).Find(&albumsList).Error
	return
}
